package cn.elwy.rcp.ui.explorer.editor;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import cn.elwy.common.util.AssertUtil;
import cn.elwy.osgi.config.util.ResourceUtil;
import cn.elwy.rcp.core.model.ui.progress.ProgressMonitor;
import cn.elwy.rcp.ui.dialog.MsgDialog;
import cn.elwy.rcp.ui.explorer.core.AppContext;
import cn.elwy.rcp.ui.explorer.core.ProjectConst;
import cn.elwy.rcp.ui.explorer.core.service.SvnManageService;
import cn.elwy.rcp.ui.explorer.core.vo.ProjectConfig;
import cn.elwy.rcp.ui.explorer.process.LoadModuleProgress;
import cn.elwy.rcp.ui.explorer.process.SvnUpdateProgress;
import cn.elwy.rcp.ui.wizard.BaseWizardPage;

public class ProjectInfoEditorPage extends BaseWizardPage {

  public static final String ID = "ProjectInfoEditorPage";

  private SvnManageService svnManageService = AppContext.getBean(SvnManageService.ID);

  private Composite container;

  PackerEditorWizard wizard;
  private Text projectPathText;
  private Label projectPathLabel;
  private Text projectNameText;

  private Text scmUrlText;
  private Label scmUrlLabel;
  private Text sourcePathText;
  private Text docPathPath;
  private Label docPathLabel;
  private Text dbscriptPathText;
  private Label demoPathLabel;
  private Text demoPathText;
  private Label projectVersionLabel;
  private Text projectVersionText;
  private Label containerPathLabel;
  private Text containerPathText;
  private Label parentPomPathLabel;
  private Text parentPomPathText;
  private Composite composite;
  private Label resourcePathLabel;
  private Label outputPathLabel;
  private Text resourcePathText;
  private Text outputPathText;
  private Label startVersionLabel;
  private Composite composite_1;
  private Text startVersionText;
  private Label currentVersionLabel;
  private Text endVersionText;
  private Button headRevisionButton;
  private Button revisionButton;
  private Button autoUpdateButton;

  private ProjectConfig projectConfig;

  /**
   * Create the wizard.
   */
  public ProjectInfoEditorPage() {
    super(ID);
    setTitle("设置构建工程配置");
    setDescription("构建工程基本配置项");
  }

  /**
   * Create contents of the wizard.
   * @param parent
   */
  public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(2, false));
    Label projectNameLabel = new Label(container, SWT.NONE);
    projectNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    projectNameLabel.setText("工程名称(&P)：");

    composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.marginWidth = 0;
    gl_composite.marginHeight = 0;
    composite.setLayout(gl_composite);

    this.projectNameText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);

    projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    projectVersionLabel = new Label(composite, SWT.NONE);
    projectVersionLabel.setText("版本号(&V)：");

    projectVersionText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
    GridData gd_projectVersionText = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_projectVersionText.widthHint = 50;
    projectVersionText.setLayoutData(gd_projectVersionText);

    this.projectPathLabel = new Label(container, SWT.NONE);
    projectPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    this.projectPathLabel.setText("工程路径：");

    this.projectPathText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    projectPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    resourcePathLabel = new Label(container, SWT.NONE);
    resourcePathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    resourcePathLabel.setText("源码路径：");

    resourcePathText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    resourcePathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    outputPathLabel = new Label(container, SWT.NONE);
    outputPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    outputPathLabel.setText("输出路径：");

    outputPathText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    outputPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    scmUrlLabel = new Label(container, SWT.NONE);
    scmUrlLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    scmUrlLabel.setText("SVN地址：");

    scmUrlText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    scmUrlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    svnUserLabel = new Label(container, SWT.NONE);
    svnUserLabel.setText("SVN用户名：");

    composite_2 = new Composite(container, SWT.NONE);
    composite_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_composite_2 = new GridLayout(4, false);
    gl_composite_2.marginWidth = 0;
    gl_composite_2.marginHeight = 0;
    composite_2.setLayout(gl_composite_2);

    svnUserText = new Text(composite_2, SWT.BORDER);
    svnUserText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    svnPasswordLabel = new Label(composite_2, SWT.NONE);
    svnPasswordLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    svnPasswordLabel.setText("SVN密码：");

    svnPasswordText = new Text(composite_2, SWT.BORDER | SWT.PASSWORD);
    svnPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

    autoUpdateButton = new Button(composite_2, SWT.CHECK);
    autoUpdateButton.setText("自动更新源码");

    startVersionLabel = new Label(container, SWT.NONE);
    startVersionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    startVersionLabel.setText("基线版本：");

    composite_1 = new Composite(container, SWT.NONE);
    composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    GridLayout gl_composite_1 = new GridLayout(6, false);
    gl_composite_1.marginWidth = 0;
    gl_composite_1.marginHeight = 0;
    composite_1.setLayout(gl_composite_1);

    startVersionText = new Text(composite_1, SWT.BORDER);
    GridData gd_startVersionText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_startVersionText.widthHint = 100;
    startVersionText.setLayoutData(gd_startVersionText);

    currentVersionLabel = new Label(composite_1, SWT.NONE);
    currentVersionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    currentVersionLabel.setText("当前版本：");

    headRevisionButton = new Button(composite_1, SWT.RADIO);
    headRevisionButton.setSelection(true);
    headRevisionButton.setText("HEAD");

    revisionButton = new Button(composite_1, SWT.RADIO);
    revisionButton.setText("Revision");

    endVersionText = new Text(composite_1, SWT.BORDER);
    GridData gd_endVersionText = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_endVersionText.widthHint = 100;
    endVersionText.setLayoutData(gd_endVersionText);

    updateStartVersionButton = new Button(composite_1, SWT.CHECK);
    updateStartVersionButton.setText("更新基线版本号");

    Label sourcePathLabel = new Label(container, SWT.NONE);
    sourcePathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    sourcePathLabel.setText("源码目录：");

    Composite composite_3 = new Composite(container, SWT.NONE);
    composite_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    GridLayout gl_composite_3 = new GridLayout(2, false);
    gl_composite_3.marginWidth = 0;
    gl_composite_3.marginHeight = 0;
    composite_3.setLayout(gl_composite_3);
    sourcePathText = new Text(composite_3, SWT.BORDER);
    sourcePathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    errorBreakButton = new Button(composite_3, SWT.CHECK);
    errorBreakButton.setText("打包异常退出");

    docPathLabel = new Label(container, SWT.NONE);
    docPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    docPathLabel.setText("文档目录：");

    docPathPath = new Text(container, SWT.BORDER);
    docPathPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    demoPathLabel = new Label(container, SWT.NONE);
    demoPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    demoPathLabel.setText("演示目录：");

    demoPathText = new Text(container, SWT.BORDER);
    demoPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    label = new Label(container, SWT.NONE);
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    label.setText("发布源码：");

    srcPathText = new Text(container, SWT.BORDER);
    srcPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label dbscriptPathLabel = new Label(container, SWT.NONE);
    dbscriptPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    dbscriptPathLabel.setText("脚本目录：");

    dbscriptPathText = new Text(container, SWT.BORDER);
    dbscriptPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    containerPathLabel = new Label(container, SWT.NONE);
    containerPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    containerPathLabel.setText("容器路径：");

    containerPathText = new Text(container, SWT.BORDER);
    containerPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    parentPomPathLabel = new Label(container, SWT.NONE);
    parentPomPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    parentPomPathLabel.setText("父POM路径：");

    parentPomPathText = new Text(container, SWT.BORDER);
    parentPomPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    toolsPathLabel = new Label(container, SWT.NONE);
    toolsPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    toolsPathLabel.setText("工具路径：");

    toolsPathText = new Text(container, SWT.BORDER);
    toolsPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    //
    // final ProjectComposite composite = new ProjectComposite(container, SWT.NONE);
    // composite.addModifyListener(new ModifyListener() {
    // public void modifyText(ModifyEvent e) {
    // Control control = (Control) e.getSource();
    // if (!e.equals(control.getData())) {
    // if (composite.isDirty()) {
    // // setDirty(true);
    // }
    // }
    // }
    // });
    // composite.addSelectionChangedListener(new ISelectionChangedListener() {
    // @Override
    // public void selectionChanged(SelectionChangedEvent event) {
    // if (composite.isDirty()) {
    // // setDirty(true);
    // }
    // }
    // });
    // GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    // composite.setLayoutData(gd_composite);

    addListener();
    init();
  }

  private void addListener() {
    scmUrlText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        validatePage();
      }
    });
    svnUserText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        validatePage();
      }
    });
    svnPasswordText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        validatePage();
      }
    });

    projectNameText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        String projectName = projectNameText.getText();
        if ("".equals(projectName.trim())) {
          return;
        }
        // boolean selection = useDefaultPathButton.getSelection();
        // if (selection) {
        // File text = new File(ResourceUtil.getWorkspacePath().getAbsolutePath(), projectName);
        // projectPathText.setText(text.getAbsolutePath());
        // }
      }
    });
    autoUpdateButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        boolean selection = autoUpdateButton.getSelection();
        if (selection) {
          projectConfig.setAutoUpdate(autoUpdateButton.getSelection());
        }
      }
    });
    headRevisionButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        endVersionText.setText("");
        endVersionText.setEditable(false);
      }
    });
    revisionButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        String endVersion = projectConfig.getEndVersion();
        endVersionText.setEditable(true);
        if (AssertUtil.isNotEmpty(endVersion) && !endVersion.equals("HEAD")) {
          endVersionText.setText(endVersion);
        } else {
          endVersionText.setText("");
        }
      }
    });
  }

  private void init() {
    wizard = (PackerEditorWizard) getWizard();
    projectConfig = wizard.getProjectConfig();
    moduleChoiceModel = wizard.getModuleChoiceModel();
    setText(projectNameText, projectConfig.getProjectName());
    setText(projectVersionText, projectConfig.getVersion());
    // projectPathButton;
    String path = projectConfig.getProjectPath();
    if (AssertUtil.isEmpty(path)) {
      path = ResourceUtil.getWorkspacePath().getAbsolutePath();
    }
    setText(projectPathText, path);

    setText(scmUrlText, projectConfig.getScmUrl());
    setText(svnUserText, projectConfig.getScmUser());
    setText(svnPasswordText, projectConfig.getScmPassword());
    setText(sourcePathText, projectConfig.getSourceDirectory());
    setText(docPathPath, projectConfig.getDocDirectory());
    setText(dbscriptPathText, projectConfig.getDbScriptDirectory());
    setText(demoPathText, projectConfig.getDemoDirectory());
    setText(srcPathText, projectConfig.getSrcDirectory());
    setText(containerPathText, projectConfig.getContainerDirectory());
    setText(parentPomPathText, projectConfig.getParentPom());
    setText(resourcePathText, projectConfig.getResourcePath());
    setText(outputPathText, projectConfig.getOutputPath());
    setText(startVersionText, projectConfig.getStartVersion());
    updateStartVersionButton.setSelection(projectConfig.isUpdateStartVersion());
    errorBreakButton.setSelection(projectConfig.isErrorBreak());

    setText(toolsPathText, projectConfig.getToolsPath());

    Event event = new Event();
    String endVersion = projectConfig.getEndVersion();
    if (AssertUtil.isEmpty(endVersion) || endVersion.equals("HEAD")) {
      event.widget = headRevisionButton;
      headRevisionButton.setSelection(true);
      revisionButton.setSelection(false);
      headRevisionButton.notifyListeners(SWT.Selection, event);
    } else {
      revisionButton.setSelection(true);
      headRevisionButton.setSelection(false);
      event.widget = revisionButton;
      revisionButton.notifyListeners(SWT.Selection, event);
    }
  }

  public void setText(Text text, String value) {
    if (value != null) {
      text.setText(value);
    }
  }

  @Override
  public Object getPageData() {
    // projectConfig.setProjectName(projectNameText.getText());
    // projectConfig.setVersion(projectVersionText.getText());
    // projectConfig.setProjectPath(projectPathText.getText());
    projectConfig.setResourcePath(resourcePathText.getText());
    projectConfig.setOutputPath(outputPathText.getText());

    projectConfig.setStartVersion(startVersionText.getText().trim());
    projectConfig.setUpdateStartVersion(updateStartVersionButton.getSelection());

    boolean selection = revisionButton.getSelection();
    if (selection) {
      projectConfig.setEndVersion(endVersionText.getText().trim());
    } else {
      projectConfig.setEndVersion(ProjectConst.HEAD);
    }

    boolean isErrorBreak = errorBreakButton.getSelection();
    projectConfig.setErrorBreak(isErrorBreak);
    // projectConfig.setScmUrl(scmUrlText.getText().trim());
    projectConfig.setScmUser(svnUserText.getText().trim());
    projectConfig.setScmPassword(svnPasswordText.getText().trim());
    projectConfig.setTestSvn(true);
    projectConfig.setAutoUpdate(autoUpdateButton.getSelection());

    projectConfig.setSourceDirectory(sourcePathText.getText().trim());
    projectConfig.setDocDirectory(docPathPath.getText().trim());
    projectConfig.setSrcDirectory(srcPathText.getText().trim());
    projectConfig.setDbScriptDirectory(dbscriptPathText.getText().trim());
    projectConfig.setDemoDirectory(demoPathText.getText().trim());
    projectConfig.setContainerDirectory(containerPathText.getText().trim());
    projectConfig.setParentPom(parentPomPathText.getText().trim());
    projectConfig.setToolsPath(toolsPathText.getText().trim());

    return projectConfig;
  }

  @Override
  public boolean validate() {
    boolean pageState = validateSvn();
    if (pageState) {
      setErrorMessage(null);
    }
    setPageComplete(pageState);
    return pageState;
  }

  private boolean validateSvn() {
    String projectName = scmUrlText.getText();
    if (AssertUtil.isEmpty(projectName)) {
      setErrorMessage("请输入SVN地址！");
      return false;
    }
    String version = svnUserText.getText();
    if (AssertUtil.isEmpty(version)) {
      setErrorMessage("请输入SVN用户名！");
      return false;
    }
    String projectPath = svnPasswordText.getText();
    if (AssertUtil.isEmpty(projectPath)) {
      setErrorMessage("请输入SVN密码！");
      return false;
    }
    return true;
  }

  public boolean testLoginSvn(ProgressMonitor monitor) {
    getPageData();
    boolean result = svnManageService.checkSvnLogin(projectConfig, monitor);
    if (!result) {
      setErrorMessage("SVN登录失败，请验证SVN地址和用户名、密码");
      setPageComplete(false);
      return false;
    } else {
      setErrorMessage(null);
      setPageComplete(true);
      return true;
    }
  }

  private ModuleChoiceModel moduleChoiceModel;
  private Label toolsPathLabel;
  private Text toolsPathText;
  private Composite composite_2;
  private Text svnUserText;
  private Label svnPasswordLabel;
  private Text svnPasswordText;
  private Label svnUserLabel;
  private Button updateStartVersionButton;
  private Label label;
  private Text srcPathText;
  private Button errorBreakButton;

  // class LongRunningOperation implements IRunnableWithProgress {
  // // The total sleep time
  // private static final int TOTAL_TIME = 5000;
  // // The increment sleep time
  // private static final int INCREMENT = 500;
  // private boolean indeterminate;
  //
  // public LongRunningOperation(boolean indeterminate) {
  // this.indeterminate = indeterminate;
  // }
  //
  // public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
  // monitor = (IProgressMonitor) new ProgressMonitor(monitor);
  // monitor.beginTask("更新SVN代码", indeterminate ? IProgressMonitor.UNKNOWN : TOTAL_TIME);
  // // monitor.subTask("Doing first half");
  // moduleChoiceModel.setProgressMonitor((ProgressMonitor) monitor);
  // moduleChoiceModel.setInput(null);
  // List<BuilderModule> moduleList = moduleChoiceModel.getInput();
  // moduleChoiceModel.setInput(moduleList);
  // monitor.beginTask("加载可以重新编译打包的模块", indeterminate ? IProgressMonitor.UNKNOWN : TOTAL_TIME);
  //
  // for (int total = 0; total < TOTAL_TIME && !monitor.isCanceled(); total += INCREMENT) {
  // Thread.sleep(INCREMENT);
  // monitor.worked(INCREMENT);
  // if (total == TOTAL_TIME / 2)
  // monitor.subTask("Doing second half");
  // }
  // monitor.done();
  // if (monitor.isCanceled())
  // throw new InterruptedException("The long running operation was cancelled");
  // }
  // }

  @Override
  public boolean nextButtonPressed() {
    boolean nextButtonPressed = super.nextButtonPressed() && testLoginSvn(new ProgressMonitor(null));
    if (!nextButtonPressed) {
      return false;
    }
    getPageData();

    if (autoUpdateButton.getSelection()) {
      try {
        SvnUpdateProgress runnable = new SvnUpdateProgress(projectConfig);
        getContainer().run(true, true, runnable);
      } catch (InterruptedException e) {
        return false;
      } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MsgDialog.open(getShell(), realException);// (getShell(), "Error", realException.getMessage());
        return false;
      }
    }
    try {
      LoadModuleProgress runnable = new LoadModuleProgress(moduleChoiceModel);
      getContainer().run(true, true, runnable);
      // runnable.getBuilderModules();
      // moduleChoiceModel.setInput(null);
      // List<BuilderModule> moduleList = moduleChoiceModel.getInput();
      // moduleChoiceModel.setInput(moduleList);
    } catch (InterruptedException e) {
      return false;
    } catch (InvocationTargetException e) {
      Throwable realException = e.getTargetException();
      MessageDialog.openError(getShell(), "Error", realException.getMessage());
      return false;
    }
    return true;

    // wizard.setCanCancel(false);
    // setPageComplete(false);
    // wizard.getEditor().setDirty(true);

    // IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
    // Job cunstomJob = new Job("执行") {
    //
    // @Override
    // protected IStatus run(IProgressMonitor monitor) {
    // monitor.beginTask("开始执行任务...", 10);
    //
    // for (int i = 0; i < 10; i++) {
    // try {
    // Thread.sleep(1000);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }
    // monitor.worked(i);
    // System.out.println(i + "");
    // }
    //
    // Display.getDefault().asyncExec(new Runnable() {
    // public void run() {
    // wizard.setCanCancel(true);
    // ProjectInfoEditorPage.this.setPageComplete(true);
    // ProjectInfoEditorPage.this.updateButtons();
    // }
    // });
    // monitor.done();
    // return Status.OK_STATUS;
    // }
    //
    // };
    //
    // cunstomJob.setUser(true);
    // cunstomJob.setPriority(Job.SHORT);
    // cunstomJob.schedule();
    // try {
    // while (cunstomJob.getState() != 0) {
    // Thread.sleep(3000);
    // }
    // // cunstomJob.join();
    // } catch (Exception e1) {
    // return false;
    // }
    // try {
    // // IWizardContainer container2 = wizard.getContainer();
    // // container2.run(true, true, new IRunnableWithProgress() {
    // // public void run(IProgressMonitor monitor) {
    // // SvnManageService service = AppContext.getService(SvnManageService.ID, SvnManageService.class);
    // // service.checkOut(projectConfig);
    // // for (int i = 0; i < 10000; i++)
    // // monitor.setTaskName("jindu" + i);
    // // }
    // // });
    // // Job job = new Job("获取数据") {
    // //
    // // protected IStatus run(final IProgressMonitor monitor) {
    // // // 在此添加获取数据的代码
    // //
    // // Display.getDefault().asyncExec(new Runnable() {
    // //
    // // public void run() {
    // // SvnManageService service = AppContext.getService(SvnManageService.ID,
    // // SvnManageService.class);
    // // service.checkOut(projectConfig);
    // // for (int i = 0; i < 10000; i++)
    // // monitor.setTaskName("jindu" + i);
    // // // monitor.beginTask("dfdsaf", 100);
    // //
    // // }
    // //
    // // });
    // // return Status.OK_STATUS;
    // //
    // // }
    // //
    // // };
    // //
    // // job.schedule();
    //
    // // progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), new IRunnableWithProgress() {
    // // public void run(IProgressMonitor monitor) {
    // // SvnManageService service = AppContext.getService(SvnManageService.ID, SvnManageService.class);
    // // service.checkOut(projectConfig);
    // // for (int i = 0; i < 10000; i++)
    // // monitor.setTaskName("jindu" + i);
    // // }
    // // }, ResourcesPlugin.getWorkspace().getRoot());
    //
    // } catch (Exception e) {
    // e.printStackTrace();
    // }

    // return true;
  }
}
